package com.dyzx.hbb.modules.sys.sql;

import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.dyzx.hbb.common.constant.InitConfig;
import com.dyzx.hbb.modules.sys.entity.SysUser;
import org.apache.commons.lang3.StringUtils;

public class SqlHelper {


    public static String getImageUrl(String avatar) {
        if (avatar != null && !avatar.isEmpty()) {
            String path = InitConfig.getPathUrl();
            return "(SELECT IF(LOCATE('http',URL) > 0,URL,CONCAT('" + path + "',URL)) FROM  sys_file WHERE ID=" + avatar + "  LIMIT 1)";
        } else {
            return "";
        }
    }

    public static String getImageUrls(String key) {
        String path = InitConfig.getPathUrl();
        return "(SELECT group_concat(IF(LOCATE('http',URL) > 0,URL,CONCAT('" + path + "',URL))) FROM  sys_file WHERE FIND_IN_SET(ID," + key + ")  LIMIT 1)";
    }

    public static String getDeptName(String deptId) {
        if (deptId != null && !deptId.isEmpty()) {
            return "(SELECT name FROM sys_dept WHERE id = " + deptId + "   LIMIT 1)";
        } else {
            return "";
        }
    }

    public static String getOrganName(String f) {
        if (f != null && !f.isEmpty()) {
            return "(SELECT name FROM sys_organ WHERE id = " + f + "   LIMIT 1)";
        } else {
            return "";
        }
    }


    public static String getUserName(String f) {
        if (f != null && !f.isEmpty()) {
            return "(SELECT name FROM sys_user WHERE id = " + f + "   LIMIT 1)";
        } else {
            return "";
        }
    }

    public static String getAddressName(String f) {
        if (f != null && !f.isEmpty()) {
            return "(SELECT tsys_address.name FROM sys_address as tsys_address WHERE tsys_address.id = " + f + "   LIMIT 1)";
        } else {
            return "";
        }
    }

    public static String getBrokerName(String f) {
        if (f != null && !f.isEmpty()) {
            return "(SELECT name FROM sys_broker WHERE id = " + f + "   LIMIT 1)";
        } else {
            return "";
        }
    }
    public static String getBrokersName(String f) {
        if (f != null && !f.isEmpty()) {
            return "(SELECT GROUP_CONCAT(name SEPARATOR ',')  FROM sys_broker WHERE FIND_IN_SET(id," + f + ")   LIMIT 1)";
        } else {
            return "";
        }
    }


    public static String getHouseName(String f) {
        if (f != null && !f.isEmpty()) {
            return "(SELECT name FROM wms_house WHERE id = " + f + "   LIMIT 1)";
        } else {
            return "";
        }
    }
    public static String getHouseLeaderId(String f) {
        if (f != null && !f.isEmpty()) {
            return "(SELECT leader_id FROM wms_house WHERE id = " + f + "   LIMIT 1)";
        } else {
            return "";
        }
    }

    public static String getWmsProductName(String f) {
        if (f != null && !f.isEmpty()) {
            return "(SELECT name FROM wms_product WHERE id = " + f + "   LIMIT 1)";
        } else {
            return "";
        }
    }

}
